<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CompanyTransferOrder extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('company_transfer_order', ['comment' => '公司调拨订单表']);
        $table->addColumn('company_id', 'integer', ['comment' => '公司id', 'limit' => 11, 'default' => 0])
            ->addColumn('order_no', 'string', ['comment' => '订单号', 'limit' => 32, 'default' => ''])
            ->addColumn('start_warehouse_id', 'integer', ['comment' => '起始仓库id', 'limit' => 11, 'default' => 0])
            ->addColumn('end_warehouse_id', 'integer', ['comment' => '目标仓库id', 'limit' => 11, 'default' => 0])
            // 调拨类型
            ->addColumn('transfer_type', 'integer', ['comment' => '调拨类型:1车销提货 2车销回库', 'limit' => 11, 'default' => 1])
            // 调拨方式
            ->addColumn('transfer_mode', 'integer', ['comment' => '调拨方式:1司机配送 2货主自提', 'limit' => 11, 'default' => 1])
            // 调拨状态
            ->addColumn('status', 'integer', ['comment' => '调拨状态:1待审批 2待出库 3待入库 4待配送', 'limit' => 11, 'default' => 1])
            // 品类数量
            ->addColumn('cate_num', 'integer', ['comment' => '品类数量', 'limit' => 11, 'default' => 0])
            // 商品数量
            ->addColumn('product_num', 'integer', ['comment' => '商品数量', 'limit' => 11, 'default' => 0])
            // 商品总额
            ->addColumn('amount', 'decimal', ['comment' => '商品总额', 'precision' => 10, 'scale' => 2, 'default' => 0.00])
            // 申请人
            ->addColumn('apply_user_id', 'integer', ['comment' => '申请人id', 'limit' => 11, 'default' => 0])
            // 审核人
            ->addColumn('audit_user_id', 'integer', ['comment' => '审核人id', 'limit' => 11, 'default' => 0])
                ->addColumn('create_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '创建时间'])
                ->addColumn('update_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '更新时间'])
                ->addColumn('delete_time', 'integer', ['limit' => 10, 'default' => null, 'comment' => '删除时间'])
            ->addIndex(['company_id'], ['name' => 'idx_company_id'])
            ->addIndex(['order_no'], ['name' => 'idx_order_no'])
            ->addIndex(['start_warehouse_id'], ['name' => 'idx_start_warehouse_id'])
            ->addIndex(['end_warehouse_id'], ['name' => 'idx_end_warehouse_id'])
            ->addIndex(['transfer_type'], ['name' => 'idx_transfer_type'])
            ->create();
    }
}
